<?php

class StrEncrypter{
    private $hex_iv = '00000000000000000000000000000000';
    private $key = "";

    public function __construct($key)
    {
        $this->key = $key;
    }

    public function encrypt($input)
    {
        $data = openssl_encrypt($input, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->hexToStr($this->hex_iv));
        $data = base64_encode($data);
        return $data;
    }

    public function decrypt($input)
    {
        $decrypted = openssl_decrypt(base64_decode($input), 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->hexToStr($this->hex_iv));
        return $decrypted;
    }

    function hexToStr($hex)
    {
        $string='';
        for ($i=0; $i < strlen($hex)-1; $i+=2)
        {
            $string .= chr(hexdec($hex[$i].$hex[$i+1]));
        }

        return $string;
    }
}

$key = "eoufoewfadkjfkd";
$se = new StrEncrypter($key);
$estr = $se->encrypt("8876");
echo $estr."<br/>";
echo $se->decrypt($estr);